package org.spdata.utils;

/**
 * 对浮点数进行缩减小数位操作的工具类
 */
public class FloatUtils {
	public static String toString(float v,int decimal){
		int i =(int) Math.pow(10, decimal);
		float r = (1.0f*Math.round(v*i))/i;
		return ""+r;
	}
	
	public static Float toShort(float v,int decimal){
		int i =(int) Math.pow(10, decimal);
		float r = (1.0f*Math.round(v*i))/i;
		return r;
	}
	
	
	public static void main(String[] args){
		
		float t = 10078.47954f;
		float td = toShort(t,3);
		
		
		for(int i=0;i<1000;i++){
			double d = Math.random();
			float f = (float)d;
			System.out.println(f+":"+toShort(f,3));
		}
	}
}
